package com.item.springmvc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 14391
 */
public class MyInterceptor implements HandlerInterceptor {

    //生成这个三个方法快捷键=>idea code =》lmplement Metod..
    //(1)preHandle -前置执行处理
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(request.getRequestURL() + "-准备执行");
        return true;
    }

    //(2)postHandle -目标资源已被Spring MVC框架处理,（return之后，但是还没产生响应文本之前）
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println(request.getRequestURL() + "-目标处理成功");
    }

    //(3)afterCompletion -响应文本已经产生
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println(request.getRequestURL() + "-响应内容已产生");
    }
}
